package com.yy.stringbuilder_;

import java.util.StringJoiner;

/**
 * chapter13  com.yy.stringbuilder_
 * 2023-05-17 19:16
 *
 * @author yy yuyue
 * description : 不可描述
 * @date 2023/5/17 19:16
 */
public class StringVsStringBufferVsStringBuilder {
    public static void main(String[] args) {

        long startTime = 0L;
        long endTime = 0L;
        StringBuffer buffer = new StringBuffer("");

        startTime = System.currentTimeMillis();
        for(int i = 0; i < 80000;i++) { //StringBuffer拼接 20000
            buffer.append(String.valueOf(i));
        }
            endTime = System.currentTimeMillis();
        System.out.println("StringBuffer的执行时间:" + (endTime-startTime));


        StringBuilder builder = new StringBuilder("");
       startTime = System.currentTimeMillis();
        for(int i = 0; i < 80000; i++){
        builder.append(String.valueOf(i));//StringBuilder拼接 20000
        }
        endTime = System.currentTimeMillis();
        System.out.println("StringBuilder的执行时间: " +
                    + (endTime - startTime));


        String text = "";
        startTime = System.currentTimeMillis();

        for(int i = 0; i < 10000; i++) {//String拼接 20000
            text = text + i;
        }
        endTime = System.currentTimeMillis();
        System.out.println("String的执行时间: " +
                + (endTime - startTime));
//        StringJoiner
    }
}
